/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public ListNode mergeKLists(ListNode[] lists) {
        ListNode head = new ListNode(0);
        ListNode tree = head;
        ArrayList<Integer> ls = new ArrayList<>();
        for(ListNode list : lists) {
            while(list != null) {
                ls.add(list.val);
                list = list.next;
            }
        }
        Collections.sort(ls);//排序
        int k=0;
        while (k < ls.size()) {
            ListNode a = new ListNode(ls.get(k++));
            tree.next = a;
            tree = tree.next;
        }
        return head.next;
    }
}